package deibay.network;

import java.io.Serializable;

import org.jdom.Document;
import org.jdom.Element;
import deibay.XmlIO;

public class Port implements Serializable{

	private Element root = null;
	private Document doc = null;
	private int port = 0;
	
	public Port()
	{		
		loadXmlPort();
	}
			
	private void createXml()
	{	
		doc = new Document();
		root = new Element("Server");
		doc.setRootElement(root);		
	}
	
	private void loadXmlPort()
	{		
		doc = XmlIO.readXML("Port.xml");
		if(doc == null)
		{
			createXml();
			XmlIO.writeXmltoFile(doc, "Port.xml");
			doc = XmlIO.readXML("Port.xml");
		}
		root = doc.getRootElement();	
		getServerPort();
	}
	
	private void getServerPort()
	{				
		port = Integer.parseInt(root.getChild("port").getValue());			
	}
	
	public int getPort()
	{
		return this.port;
	}
	
}
